package com.controller;

import com.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserContorller {
    @RequestMapping("/getUserId")
    public  void getUserId(HttpServletRequest request) {
        String userId = request.getParameter("userid");
        System.out.println("userid=" + userId);
    }

    @RequestMapping("/getUserAnName")
    public  void getUserAnName(String userName, Integer id) {
        System.out.println("userName=" + userName  + ",id=" + id);
    }

    @RequestMapping("/getUserName")
    public  void getUserName (@RequestParam(value = "name", required = false,defaultValue = "defaultName") String userName) {
        System.out.println("userName=" + userName );
    }

    @RequestMapping("/registerUser")
    public  void registerUser(User user) {
        System.out.println("user=" + user.getUsername());
        System.out.println("password=" + user.getPassword());
    }

    @RequestMapping("/findOrderWithUser")
    public void findOrderWithUser(User user) {
        String username = user.getUsername();
        String orderId = user.getOrder().getOrderId();
        System.out.println("username=" + username + ",orderId=" + orderId);
    }

    @RequestMapping("/user")
    public String user(Model model) {
        User user = new User();
        user.setUsername("张三");
        user.setPassword("123456");
        return "user";
    }

    @RequestMapping("/oser")
    public String oser() {
        ModelAndView mv=new ModelAndView();
        User user = new User();
        user.setUsername("李四");
        user.setPassword("123456");
        mv.addObject("user", user);
        mv.setViewName("user");
        return "user";
    }
}
